﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Rendering.OnDemandRendering
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Runtime.CompilerServices;
using UnityEngine.Bindings;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine.Rendering
{
  /// <summary>
  ///         <para>Use the OnDemandRendering class to control and query information about your application's rendering speed independent from all other subsystems (such as physics, input, or animation).
  /// </para>
  ///       </summary>
  [RequiredByNativeCode]
  public class OnDemandRendering
  {
    private static int m_RenderFrameInterval = 1;

    /// <summary>
    ///   <para>True if the current frame will be rendered.</para>
    /// </summary>
    public static bool willCurrentFrameRender
    {
      get => Time.frameCount % OnDemandRendering.renderFrameInterval == 0;
    }

    /// <summary>
    ///   <para>Get or set the current frame rate interval. To restore rendering back to the value of Application.targetFrameRate or QualitySettings.vSyncCount set this to 0 or 1.</para>
    /// </summary>
    public static int renderFrameInterval
    {
      get => OnDemandRendering.m_RenderFrameInterval;
      set => OnDemandRendering.m_RenderFrameInterval = Math.Max(1, value);
    }

    [RequiredByNativeCode]
    internal static void GetRenderFrameInterval(out int frameInterval)
    {
      frameInterval = OnDemandRendering.renderFrameInterval;
    }

    [FreeFunction]
    [MethodImpl(MethodImplOptions.InternalCall)]
    internal static extern float GetEffectiveRenderFrameRate();

    /// <summary>
    ///   <para>The current estimated rate of rendering in frames per second rounded to the nearest integer.</para>
    /// </summary>
    public static int effectiveRenderFrameRate
    {
      get
      {
        float effectiveRenderFrameRate = OnDemandRendering.GetEffectiveRenderFrameRate();
        return (double) effectiveRenderFrameRate <= 0.0 ? (int) effectiveRenderFrameRate : (int) ((double) effectiveRenderFrameRate + 0.5);
      }
    }
  }
}
